import React from 'react';
import { Typography } from 'antd';
import { TextWidget } from '@inbiz/react';

const { Paragraph } = Typography;

type SourceProps = {
  type: number;
  Creator: string;
  CreateTime: string;
  showField: Array<string>;
  Summary?: string;
};

const Source: React.FC<SourceProps> = (props) => {
  const { type, Creator, CreateTime, showField, Summary } = props;
  const prefixCls = 'inbiz-News';
  return (
    <>
      {type === 1 ? (
        <div className={`${prefixCls}-source width-fixed`}>
          {showField?.indexOf('creator') > -1 && <span>{Creator}</span>}
          {showField?.indexOf('createTime') > -1 && <span>{CreateTime}</span>}
        </div>
      ) : type === 2 ? (
        <div className={`${prefixCls}-source`}>
          <span>{Creator}</span>
          <span>
            <TextWidget>News.tips.created_on</TextWidget>
          </span>
          <span>{CreateTime}</span>
        </div>
      ) : (
        <>
          <div className={`${prefixCls}-summary ${prefixCls}-summary-card`}>
            <Paragraph ellipsis={{ rows: 2 }}>
              <span dangerouslySetInnerHTML={{ __html: Summary }} />
            </Paragraph>
          </div>
          <div className={`${prefixCls}-source ${prefixCls}-source-card`}>
            <span>{Creator}</span>
            <span>
              <TextWidget>News.tips.created_on</TextWidget>
            </span>
            <span>{CreateTime}</span>
          </div>
        </>
      )}
    </>
  );
};

export default Source;
